﻿@{
    Layout = null;
    string openid = ViewBag.openid;
}

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>抽奖</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="email=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <script src="~/js/jquery.js"></script>
    <script src="~/js/jweixin-1.0.0.js"></script>
    @*关于微信端的配置*@
    <script>
        var AppId = "@ViewBag.appid";
        var AppSercret = "@ViewBag.appsecret";
        var timestamp = "@ViewBag.timestamp";
        var nonceStr = "@ViewBag.nonceStr";
        var signature = "@ViewBag.signature";
    </script>
    <script src="~/js/jQueryRotate.2.1.js"></script>
    <script src="@Url.Content("~/js/DailyTaskCommon.js")?a=@(new Random().Next())"></script>
    <link href="@Url.Content("~/css/DailyTask/basic.css")?a=@(new Random().Next())" rel="stylesheet" />
    <script>
        (function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () { var clientWidth = docEl.clientWidth < 768 ? docEl.clientWidth : 768; if (!clientWidth) return; docEl.style.fontSize = 16 * (clientWidth / 320) + 'px'; }; recalc(); if (!doc.addEventListener) return; win.addEventListener(resizeEvt, recalc, false); })(document, window);
    </script>

    <script type="text/javascript">
        function GetRandomNum(Min, Max) {
            var Range = Max - Min;
            var Rand = Math.random();
            return (Min + Math.round(Rand * Range));
        }
    </script>

    <script type="text/javascript">
        var perAngle = 60;//每个奖品所占的角度
        var resultTexts = ["1角红包", "谢谢参与", "5元红包", "2元红包", "1元红包", "5角红包"];
        var resultMonney = [0.1, 0, 5, 2, 1, 0.5];
        var zjResult = '@ViewBag.ZjResult';
        var sumGold = '@ViewBag.sumGold';
        var rotating = false;
        var rotateFunc = function (angle) {
            $("#dial").rotate({
                angle: 0,
                animateTo: angle + 1800,
                duration: 8000,
                callback: function () {
                    var pstdata = $("#safeForm").serialize() + "&openid=@openid&result=" + zjResult;
                    $.ajax(
                        {
                            url: '@Url.Action("ZpGameResultReceipt", "DailyTask")',
                            data: pstdata,
                            type: 'post',
                            dataType: 'json',
                            success: function (data) {
                                rotating = false;
                                if (data.succss == 1) {
                                    if (zjResult != 2) {
                                        $(".win").show(1).delay(4000).hide(1);
                                        $(".resultText").text(resultTexts[zjResult - 1]);
                                    } else {
                                        $("#win02").show(1).delay(4000).hide(1);
                                    }
                                    $("#spzjf").text(data.syGold);
                                    sumGold = data.syGold;
                                }
                                else {
                                    if (data.syGold < 0) {         //金币不足
                                        $("#win03").show(1).delay(4000).hide(1);
                                        $("#spzjf").text(data.syGold + 500); //由于金币不足，金币肯定没有扣成功，所以加上500才是正确的剩余金币
                                    }
                                }
                                zjResult = data.zcResult;
                            }
                        }
                        );
                }
            });
        }

        function showLoading() {
            var margintop = (document.documentElement.clientHeight) / 2 - 20;
            var marginleft = (document.documentElement.clientWidth) / 2 - 20;
            $("#subLoadDiv").css({ "margin-top": margintop, "margin-left": marginleft });
            $("#loadDiv").show();
        }
        function hideLoading() {
            $("#loadDiv").hide();
        }


        function getJpResult() {
            var result = GetRandomNum(1, 6);
            if (result == 1000 / 2) {
                return result;
            } else {
                return parseInt(zjResult);
            }
            return result;
        }
        function initEvent() {
            $("#pointer").click(function () {
                rstart();
            });

            $("#aTixian").click(TiXian);

            $("#aChongWan").click(rstart);
        }


        function rstart() {

            if (!rotating) {
                //先判断金币够不够
                if (sumGold < 500) {
                    $("#win03").show(1).delay(4000).hide(1);
                    return;
                }
                var result = getJpResult();
                var turnAngel = (result - 1) * perAngle + perAngle / 2;
                rotateFunc(turnAngel);
                rotating = true;
            }
        }
        function showWin(selector) {
            $(selector).show();
        }
        $(function () {
            initEvent();
        });
        function TiXian() {
            $.ajax({
                url: '@Url.Action("TiXian", "DailyTask")',
                data: { openid: '@openid', weixinId: '@ViewBag.weixinId' },
                type: 'post',
                beforeSend: function () {
                    showLoading();
                },
                complete: function () {
                    hideLoading();
                },
                success: function (data) {
                    alert(data);
                }
            });
        }
    </script>
</head>
<body class="tt">
    <div class="content" id="content">
        <h2>您目前的金币总数：<span id="spzjf">@ViewBag.sumGold</span></h2>
        <p class="content_font">注：每500金币换一次摇奖金币</p>
        <div class="lottery" id="lottery">
            <p id="dial">
                <img src="~/images/DailyTask/dial.png">
            </p>
            <p id="pointer">
                <img src="~/images/DailyTask/pointer.png">
            </p>
        </div>
        <p class="content_font02">
            <a href="javascript:void(0)" id="aTixian">
                <img src="~/images/DailyTask/content_img01.png"></a><a href="javascript:void(0)" id="aChongWan"><img src="~/images/DailyTask/content_img02.png"></a>
        </p>
        <div class="win">
            <h3 class="resultText"></h3>
            @*<p class="win_font01">
                恭喜你获得<span class="resultText"></span><br>
                分享给朋友，签到一起来赚钱吧
            </p>
            <p class="win_font02">
                <a href="#">
                    <img src="~/images/DailyTask/content_img01.png"></a>
            </p>*@
        </div>
        <div class="win02" id="win02" style="display: none">
            <h3>
                <img src="~/images/DailyTask/win_img02.png"></h3>
            <p class="win_font01">好遗憾没有中奖</p>
        </div>
        <div class="win02" id="win03" style="display: none">
            <h3>
                <img src="~/images/DailyTask/win_img03.png"></h3>
            <p class="win_font01">
                哦哦，金币不够了！<br />
                赚够500金币再来摇奖吧！
            </p>
        </div>
    </div>


    <div style="width: 100%; height: 100%; display: none; position: absolute; top: 0px; left: 0px;" id="loadDiv">
        <div id="subLoadDiv">
            <img src="@Url.Content("~/images/load.gif")" />
        </div>
    </div>
    <form id="safeForm">
        @Html.AntiForgeryToken()
    </form>
</body>
<script type="text/javascript">
    var height = document.documentElement.clientHeight;
    var content = document.getElementById("content");
    content.style.minHeight = height + 'px';
</script>


</html>
